package com.zykj.thread.concurrent.atomic;

import java.util.Random;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author zhoulj(周利军) [1217102780@qq.com]
 * @Module ID:   <(模块)类编号，可以引用系统设计中的类编号>
 * @Comments: <对此类的描述，可以引用系统设计中的描述>
 * @JDK version used:      <JDK1.8> 39
 * @since 2019/1/15-10:39
 */
public class Demo {
    private static AtomicInteger count = new AtomicInteger(100);

    public static void main(String[] args) {


        for (int i = 0; i < 10; i++) {
            new Thread(new Runnable() {
                public void run() {
                    while (true) {
                        try {
                            Thread.sleep(1000);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                        if (count.get() > 0) {
                            int tempint = count.decrementAndGet();
                            System.out.println(Thread.currentThread().getName()+", 还剩票数:" + tempint);
                        } else {
                            System.out.println(Thread.currentThread().getName()+", 售罄！！");
                        }
                    }

                }
            }).start();
        }
    }

}
